import { addDBStore, clearDBStore, createDBStore, deleteDBStore, getDBStore } from '@/utils/dbStore'

export interface IFileStoreDB {
  id: string
  base64: string
}

const TablesName = 'fileTables'

// 创建文件存储数据库
export const createFileDBStore = (): IDBObjectStore => {
  return createDBStore(TablesName, [{ key: 'base64', unique: false }], { autoIncrement: false })
}

// 添加文件数据
export const addFileDBStore = async (id: string, base64: string): Promise<void> => {
  await addDBStore(TablesName, { id, base64 })
}

// 获取文件数据
export const getFileDBStore = (id: string): Promise<IFileStoreDB> => {
  return getDBStore<IFileStoreDB>(TablesName, id)
}

// 删除文件数据
export const deleteFileDBStore = (id: string): Promise<void> => {
  return deleteDBStore(TablesName, id)
}

// 清空File数据
export const clearFileDBStore = (): Promise<void> => {
  return clearDBStore(TablesName)
}
